//
//  MONoticeSendViewCell.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/6/10.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MONoticeSendViewCell.h"

@interface MONoticeSendViewCell ()

@property(nonatomic,strong)UIButton *selectedButton;

@property(nonatomic,strong)UILabel *nameLabel;

@end

@implementation MONoticeSendViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    //NSString *ID = [NSString stringWithFormat:@"Cell%ld%ld",(long)[indexPath section],(long)[indexPath row]];
    NSString *ID = @"MONoticeSendViewCell";
    MONoticeSendViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil){
        cell = [[MONoticeSendViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell creatView];
    }
    return cell;
}


-(void)creatView
{
    [self addSubview:self.selectedButton];
    [self addSubview:self.nameLabel];
}


-(void)setModel:(MONoticeSendModel *)model
{
    self.nameLabel.text = model.nameStr;
    if ([model.selectedTypeStr integerValue]==1) {
        [_selectedButton setImage:IMAGE(@"office_selected") forState:UIControlStateNormal];
    }else{
        [_selectedButton setImage:IMAGE(@"office_normal") forState:UIControlStateNormal];
    }
    CGFloat height = [NSString labelAutoCalculateRectWith:model.nameStr WithFont:FONT_SIZE(14) MaxSize:CGSizeMake(self.nameLabel.width, MAXFLOAT)].height;
    self.nameLabel.height = height;
    
    self.selectedButton.centerY = kHConversions(20) + height/2;
}


+ (CGFloat)heightForMONoticeSendViewCellAndModel:(MONoticeSendModel *)model
{
    CGFloat height = [NSString labelAutoCalculateRectWith:model.nameStr WithFont:FONT_SIZE(14) MaxSize:CGSizeMake(SCREEN_WIDTH - kWConversions(49) - kWConversions(19), MAXFLOAT)].height;
    return height + kHConversions(20) * 2;
    
}

#pragma mark -- 懒加载
-(UIButton *)selectedButton
{
    if (!_selectedButton) {
        _selectedButton = [[UIButton alloc]initWithFrame:CGRectMake(kWConversions(23), 0, kWConversions(15), kWConversions(15))];
        _selectedButton.userInteractionEnabled = NO;
    }
    return _selectedButton;
}

-(UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(kWConversions(49), kHConversions(20), SCREEN_WIDTH - kWConversions(49) - kWConversions(19), 1)];
        _nameLabel.numberOfLines = 0;
        _nameLabel.textColor = KBlackColor_2A2A2A;
        _nameLabel.font = FONT_SIZE(14);
    }
    return _nameLabel;
}


@end
